<?php
class ModelCatalogFaq extends Model {		
	public function addFaq($product_id, $data) {
		$data['product_id'] = $product_id;
		$data['author'] = $data['name'];
		$data['customer_id'] = $this->customer->getId();
		$data['date_added'] = $GLOBALS['V5_NOW'];
		$this->db->insert('faq', $data);
	}
		
	public function getFaqsByProductId($product_id, $start = 0, $limit = 20) {
		if ($start < 0) $start = 0;
		if ($limit < 1) $limit = 20;
		
		$query = $this->db->query("SELECT * FROM @@faq WHERE product_id = " . (int)$product_id . " AND status = 1 ORDER BY faq_id DESC LIMIT " . (int)$start . "," . (int)$limit);
			
		return $query->rows;
	}

	public function getTotalFaqsByProductId($product_id) {
		return $this->db->queryOne("SELECT COUNT(*) AS total FROM @@faq WHERE product_id = $product_id AND status = 1");
	}
}
?>